<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>订单绑定</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <link rel="stylesheet" href="/static/ztree/css/metroStyle/metroStyle.css">
    <script src="/static/js/jquery.min.js" charset="utf-8"></script>
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script src="/static/js/ztree.js" charset="utf-8"></script>
    <script src="/static/js/excheck.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            学生信息：
            <div class="layui-form-item">

                <label for="studentCode" class="layui-form-label">
                    <span class="x-red">*</span> 学生编码
                </label>
                <input type="hidden"  id="studentId" name="studentId"
                       th:value="${student.id}">
                <div class="layui-input-inline" >
                    <input type="text"  id="studentCode" name="studentCode" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${student.studentCode}">
                </div>
                <label for="studentName" class="layui-form-label">
                    <span class="x-red">*</span> 学生姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="studentName" name="studentName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${student.studentName}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="gradeDesc" class="layui-form-label">
                    <span class="x-red">*</span> 年级
                </label>
                <div class="layui-input-inline">
                    <input type="hidden" id="grade" name="grade"   required="" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${student.grade}" >

                    <input type="text" id="gradeDesc" name="gradeDesc" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${student.gradeDesc}" readonly>
                </div>
                <label for="school" class="layui-form-label">
                    <span class="x-red">*</span> 学校
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="school" name="school" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${student.school}" readonly>
                </div>
            </div>
            <HR style="color: black" SIZE=3>
            订单信息：
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">预补科目: </label>
                <div class="layui-input-block">
                    <input type="checkbox" name="" lay-skin="primary" value="1" title="语文" >
                    <input type="checkbox" name="" lay-skin="primary" value="2" title="数学">
                    <input type="checkbox" name="" lay-skin="primary" value="3" title="英语" >
                    <input type="checkbox" name="" lay-skin="primary" value="4" title="物理">
                    <input type="checkbox" name="" lay-skin="primary" value="5" title="化学" >
                    <input type="checkbox" name="" lay-skin="primary" value="6" title="生物" >
                    <input type="checkbox" name="" lay-skin="primary" value="7" title="政治">
                    <input type="checkbox" name="" lay-skin="primary" value="8" title="历史" >
                    <input type="checkbox" name="" lay-skin="primary" value="9" title="地理" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="orderType" class="layui-form-label">
                    <span class="x-red">*</span>选购类型
                </label>
                <div class="layui-input-inline">
                    <select id="orderType" name="orderType" lay-filter="orderType" onchange ="changePrice()">
                        <option value="1">A级课程</option>
                        <option value="2">1对1</option>
                        <option value="3">1对2</option>
                        <option value="4">3-6班组</option>
                        <option value="5">7-12班组</option>
                    </select>
                </div>
                <label for="price" class="layui-form-label">
                    <span class="x-red">*</span>课时价格：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="price" name="price" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${price}" readonly>
                </div>

            </div>

            <div class="layui-form-item">
                <label for="payMoney" class="layui-form-label">
                    <span class="x-red">*</span> 缴纳金额：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="payMoney" name="payMoney" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" onblur="changeDiscount()">
                </div>
                <label for="discount" class="layui-form-label">
                    <span class="x-red">*</span> 折扣 (折)
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="discount" name="discount" required="" lay-verify="required" placeholder="9.5，9，8.8，8.5，8"
                           autocomplete="off" class="layui-input" >
                </div>
            </div>


            <div class="layui-form-item">
                <button  class="layui-btn" lay-filter="add" lay-submit="" style="margin-left: 111px;">
                    提交
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(add)',function(data){
                var courses = $("input[type='checkbox']:checked");
                var course ="";
                for(var i = 0 ; i <courses.length; i ++ ){
                    if(course == ""){
                        course = $(courses[i]).attr("value");
                    }else{
                        course += ","+$(courses[i]).attr("value");
                    }
                }
                $.ajax({
                    url:"/order/add",
                    type:"post",
                    dateType:'json',
                    data:{
                        "studentId":data.field.studentId,
                        "classLevel":data.field.grade,
                        "extand1":course,
                        "extand2":data.field.orderType,
                        "extand3": data.field.price,
                        "payMoney": data.field.payMoney,
                        "discountStr" :data.field.discount
                    },
                    success:function(result){
                        if(result.code == 0){
                            layer.alert("添加成功",{icon:6},function(){
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        }

                    }
                });
                return false;
            });

            form.on('select(orderType)', function(data){
                var orderType=data.value;
                var grade     = $("#grade").val();
                $.ajax({
                    url:"/order/price",
                    type:"post",
                    dateType:'json',
                    data:{
                        "orderType" : orderType,
                        "grade" : grade
                    },
                    success:function(data){
                        $("#price").val(data.price);

                    }
                });

            });




        });

    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });
    });


    function changeDiscount(){
        var payMoney = $("#payMoney").val();
        if(payMoney != ''){
            $.ajax({
                url:"/order/discount",
                type:"post",
                dateType:'json',
                data:{
                    "payMoney" : payMoney
                },
                success:function(data){
                    $("#discount").val(data.discountStr);

                }
            });
        }




    }



</script>

</body>

</html>
